<template>
  <div id="app">
    <h2>测试题</h2>
    <SubjectItem :numData="data" @input="changeData"></SubjectItem>
    <div>
      <FlagItem :data="data"></FlagItem>
    </div>
  </div>
</template>

<script>
import FlagItem from './components/FlagItem.vue';
import SubjectItem from './components/SubjectItem.vue';
export default {
  data() {
    return {
      data: [{
        id: 1,
        num1: Math.floor(Math.random() * 20) + 1,
        num2: Math.floor(Math.random() * 20) + 1,
        total: '',
        isFinish: '未完成'
      },
      {
        id: 2,
        num1: Math.floor(Math.random() * 20) + 1,
        num2: Math.floor(Math.random() * 20) + 1,
        total: '',
        isFinish: '未完成'
      },
      {
        id: 3,
        num1: Math.floor(Math.random() * 20) + 1,
        num2: Math.floor(Math.random() * 20) + 1,
        total: '',
        isFinish: '未完成'
      },
      {
        id: 4,
        num1: Math.floor(Math.random() * 20) + 1,
        num2: Math.floor(Math.random() * 20) + 1,
        total: '',
        isFinish: '未完成'
      },
      {
        id: 5,
        num1: Math.floor(Math.random() * 20) + 1,
        num2: Math.floor(Math.random() * 20) + 1,
        total: '',
        isFinish: '未完成'
      }]
    }
  },
  components: {
    FlagItem,
    SubjectItem
  },
  methods: {
    changeData(item) {
      if (item.total == '') return item.isFinish = '未完成'
      item.isFinish = item.total == item.num1 + item.num2 ? '回答正确' : '回答错误'
    }
  }

};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>